#include "SkinManager.h"

namespace Lame3d
{
	const char* _skinExts[] = {"skin", NULL};
	
	SkinManager::SkinManager(FontManager &fM, const DisplayManager &dM, const char *path)
			: textureManager(path), fontManager(fM), displayManager(dM)
	{		
		Directory directory(path, _skinExts);
		std::map<std::string, File*>::const_iterator it;
		for(it = directory.FileIterator(); it != directory.End(); ++it) {
			printf("adding skin: %s from path: %s...", it->first.c_str(), it->second->GetPath().c_str());
			UISkin *nSkin = new UISkin(*it->second, textureManager, fontManager, displayManager);
			skins[nSkin->Name()] = nSkin;
			printf(" using name %s\n", nSkin->Name().c_str());
		}
	}
	
	SkinManager::~SkinManager()
	{
		std::map<std::string, UISkin*>::iterator it;
		for(it = skins.begin(); it != skins.end(); ++it) {
			delete it->second;
		}
	}
	
	UISkin& SkinManager::operator[](const std::string &name)
	{
		std::map<std::string, UISkin*>::iterator it;
		it = skins.find(name);
		if(it == skins.end()) {
			throw "Couldn't find given skin!";
		}
		return *it->second;
	}
}

// eof //
